package com.gonsin.base;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.ToString;
import springfox.documentation.annotations.ApiIgnore;

import java.io.Serializable;

/*返回结果类*/
@ApiIgnore
@ApiModel("返回结果的泛型结构")
@ToString
public class ResponseResult<T> implements Serializable {

    private static final long serialVersionUID = -2174026817950983890L;

    private ResponseResult(){}

    @ApiModelProperty(value = "返回码", example = "200")
    private Integer state = 200;//响应状态码

    @ApiModelProperty("响应信息")
    private String message;//响应信息

//    @ApiModelProperty(value = "【S06开始的接口，都弃用该字段】当前页面, 从0开始，如果查询的是全部（不翻页）或者非查询，则为-1", hidden = true)
//    @Deprecated
//    private Integer page = -1;
//
//    @Deprecated
//    @ApiModelProperty(value = "【S06开始的接口，都弃用该字段】当前总页数，如果查询的是全部（不翻页）或者非查询，则为-1", hidden = true)
//    private Integer pageCount = -1;

    @ApiModelProperty("相应数据")
    private T data;//响应数据

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    private ResponseResult(Integer state, String message, T data) {
        this.state = state;
        this.message = message;
        this.data = data;
    }

//    private ResponseResult(Integer state, String message, T data, int page, int pageCount) {
//        this.state = state;
//        this.message = message;
//        this.data = data;
//        this.page = page;
//        this.pageCount = pageCount;
//    }

    private ResponseResult(Integer state, String message) {
        this.state = state;
        this.message = message;
    }

    public static <D> ResponseResult<D> result(D data) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.state = 200;
        responseResult.message = "";
        responseResult.setData(data);
        return responseResult;
    }

//    public static <D> ResponseResult<D> result(D data, int page, int pageCount) {
//        ResponseResult responseResult = new ResponseResult();
//        responseResult.state = 200;
//        responseResult.message = "";
//        responseResult.page = page;
//        responseResult.pageCount = pageCount;
//
//        responseResult.setData(data);
//        return responseResult;
//    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static ResponseResult<Void> simpleResult(){
        return new ResponseResult<Void>();
    }

    public static ResponseResult simpleResult(Integer state){
        return new ResponseResult<>(state, null);
    }

    public static ResponseResult simpleResult(Integer state, String message){
        return new ResponseResult<>(state, message);
    }

//    public int getPage() {
//        return page;
//    }
//
//    public void setPage(int page) {
//        this.page = page;
//    }
//
//    public int getPageCount() {
//        return pageCount;
//    }
//
//    public void setPageCount(int pageCount) {
//        this.pageCount = pageCount;
//    }
}

